<div class="pageContent uiComplete">
    <form method="post"
        action="${rc.getContextPath()}/manage/messageRule/saveMessageRule"
        class="pageForm required-validate"
        onsubmit="return validateCallback(this, dialogAjaxDone);">
        <div class="pageFormContent"  <#if  (messageRule)??>layoutH="120"<#else>layoutH="50"</#if> >
            <input type="hidden" name="navTabId" value="">
            	<input type="hidden" name="id"
                value="<#if (messageRule.id)??>${messageRule.id!''}</#if>">
            
            <fieldset class="dataset">
                <dl>
                    <dt><@label key="messageRuleCode.C,colon">消息规则编号：</@label></dt>
                    <dd>
                        <input name="ruleCode"
                            size="32" type="text" maxlength="20" class="required alphanumeric toUp textInput" 
                            <#if (messageRule)??>
                                value="${messageRule.ruleCode!''}" readonly="readonly"
                            <#else>
	                                remote="${rc.getContextPath()}/manage/messageRule/validateMessageRuleCodeExist"
	                            warn="<@label key="messageRuleCodeExist.M">消息通知规则编码已存在</@label>"
                            </#if>
                        /> 
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="desc.C,colon">描述：</@label></dt>
                    <dd>
                        <input name="ruleText"
                            size="32" type="text" maxlength="60" class="required textInput " 
                            <#if (messageRule)??>
                                value="${messageRule.ruleText!''}" 
                            </#if>
                            /> 
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="andonType.C,colon">ANDON类型：</@label></dt>
                    <dd>
                        <select name="andonTypeCode">
                            <option value="" ><@label key="all.C">所有</@label></option>
                            <#list andonTypeList  as andonType>
                            <option value="${andonType.andonTypeCode}"<#if  (messageRule)?? && andonType.andonTypeCode == messageRule.andonTypeCode> selected="selected"</#if>>${andonType.typeText}</option>
                            </#list>
                        </select>
                    </dd>
                </dl>
                <dl>
                    <dt>&nbsp;</dt>
                    <dd>
                        <label style="width:80px;">
                            <input name="lockFlag" type="checkbox" value="1"  <#if (messageRule)?? && 1==messageRule.lockFlag>checked="true"</#if>/> 
                            <@label key="lock.C">锁定</@label>
                        </label>
                    </dd>
                </dl>
                <dl  class="nowrap">
                    <dt><@label key="andonChoose.C,colon">ANDON选择：</@label></dt>
                    <dd>
                        <div style="float:left;'">
                        <input name="allAndonsFlag" type="checkbox" value="1"  <#if (messageRule)?? && 1==messageRule.allAndonsFlag>checked="true"</#if>/> 
                        <@label key="all.C">所有</@label>
                        </div>
                        <div  style="float:left;margin-left:20px;">
	                        <div class="buttonActive">
	                        <div class="buttonContent">
	                            <button type="button" name="btnAndonSelect" <#if (messageRule)?? && 1==messageRule.allAndonsFlag>disabled</#if>><@label key="choose.B">选择</@label></button>
	                        </div>
                        </div>
                    </div>
                        
                    </dd>
                </dl>
                <dl  class="nowrap">
                        <div >
                            <table class="table border" style="width:100%;"  <#if  (messageRule)?? >layoutH="450"<#else>layoutH="385"</#if>>
                                <thead>
                                    <tr>
                                        <th width="50"><@label key="workCenter.C">工作中心</@label></th>
                                        <th width="50"><@label key="workUnit.C">作业单元</@label></th>
                                        <th width="50"><@label key="type.C">类型</@label></th>
                                        <th width="50"><@label key="andonCode.C">ANDON编号</@label></th>
                                        <th width="20"><@label key="opera.C">操作</@label></th>
                                    </tr>
                                </thead>
                                <tbody name="ruleAndonAssign_tbody">
                                    <#if (messageRule)?? && (messageRule.messageRuleAndonAssignList)??>
                                    <#list messageRule.messageRuleAndonAssignList as messageRuleAndonAssign>
                                        <tr name="${messageRuleAndonAssign.workUnitCode}_${messageRuleAndonAssign.andonCode}">
                                            <td><input type='hidden'  name='messageRuleAndonAssignList[${messageRuleAndonAssign_index}].workUnitCode' value="${messageRuleAndonAssign.workUnitCode!''}"/><input type='hidden'  name='messageRuleAndonAssignList[${messageRuleAndonAssign_index}].andonCode'  value="${messageRuleAndonAssign.andonCode!''}"/>${messageRuleAndonAssign.workCenterText!''}</td>
                                            <td>${messageRuleAndonAssign.workUnitText!''}</td>
                                            <td>${messageRuleAndonAssign.andonTypeText!''}</td>
                                            <td>${messageRuleAndonAssign.andonCode!''}</td>
                                            <td><a title="<@label key="delete.B">删除</@label>" class="btnDel"><@label key="delete.B">删除</@label></a></td>
                                        </tr>
                                    </#list>
                                    </#if>
                                </tbody>
                            </table>
                        </div>
                </dl>
                <dl  class="nowrap">
                        <div>
                            <div id="bar" class="panelBar border">
	                            <ul class="toolBar">
	                                <li><a class="add" rel="messageRuleItemAdd_dialog" name="btnMessageRuleItemAdd" lookupGroup="messageRuleItem" href="${rc.getContextPath()}/manage/messageRule/toAddMessageRuleItem" width="600" height="300">
	                                <span><@label key="add.B">新增</@label></span></a></li>
	                                <li><a class="delete" name="btnMessageRuleItemDel"><span><@label
                                                key="delete.B">删除</@label></span></a></li>
	                            </ul>
                            </div>
                            <table class="table border" style="width:100%;"  <#if  (messageRule)?? >layoutH="450"<#else>layoutH="385"</#if>>
                                <thead>
                                    <tr>
                                        <th width="20"><input type="checkbox" group="rule_id"  class="checkboxCtrl"/></th>
                                        <th width="100"><@label key="noticePeriod.C">通知时段</@label></th>
                                        <th width="50"><@label key="timerStartEcode.C">计时起点</@label></th>
                                        <th width="50"><@label key="monitorStatus.C">监控状态</@label></th>
                                        <th width="60"><@label key="messageReceiveUser.C">消息接收人</@label></th>
                                        <th width="40"><@label key="timeInterval.C">升级时限</@label></th>
                                        <th width="100"><@label key="messageTemplate.C">消息模版</@label></th>
                                    </tr>
                                </thead>
                                <tbody name='messageRuleItem_tbody'>
                                    <#if (messageRule)?? && (messageRule.messageRuleItemList)??>
                                    <#list messageRule.messageRuleItemList as messageRuleItem>
                                        <tr ref="${messageRuleItem.id}">
                                            <td><input type='checkbox' name='rule_id'' value='${messageRuleItem.id}'>
                                                    <input type='hidden' name='messageRuleItemList[${messageRuleItem_index}].id'' value='${messageRuleItem.id}'>
                                                    <input type='hidden' group="delete" name='messageRuleItemList[${messageRuleItem_index}].delete'' value="false"></td>
                                            <td><input type='hidden'  name='messageRuleItemList[${messageRuleItem_index}].periodStart' value="${messageRuleItem.periodStart!''}"/><input type='hidden'  name='messageRuleItemList[${messageRuleItem_index}].periodEnd'  value="${messageRuleItem.periodEnd!''}"/>${messageRuleItem.periodStart!''} - ${messageRuleItem.periodEnd!''}</td>
                                            <td><input type='hidden'  name='messageRuleItemList[${messageRuleItem_index}].timerStartEcode' value="${messageRuleItem.timerStartEcode!''}"/>${messageRuleItem.timerStartEcodeText!''}</td>
                                            <td><input type='hidden'  name='messageRuleItemList[${messageRuleItem_index}].statusEcode' value="${messageRuleItem.statusEcode!''}"/>${messageRuleItem.statusEcodeText!''}</td>
                                            <td><input type='hidden'  name='messageRuleItemList[${messageRuleItem_index}].receiveUser' value="${messageRuleItem.receiveUser!''}"/>${messageRuleItem.receiveUserText!''}</td>
                                            <td><input type='hidden'  name='messageRuleItemList[${messageRuleItem_index}].timeInterval'  value="${messageRuleItem.timeInterval!''}"/>${messageRuleItem.timeInterval!''}<@label key="second.C">秒</@label></td>
                                            <td><input type='hidden'  name='messageRuleItemList[${messageRuleItem_index}].messageCode'  value="${messageRuleItem.messageCode!''}"/>${messageRuleItem.messageText!''}</td>
                                        </tr>
                                    </#list>
                                    </#if>
                                </tbody>
                            </table>
                        </div>
                </dl>
            </fieldset>
        </div>
        <#if (messageRule)??>
            <#assign createInfo=messageRule>
            <#include "/common/createInfo.html">
        </#if>
        <div class="formBar">
            <ul>
                <li>
                    <div class="buttonActive">
                        <div class="buttonContent">
                            <button type="submit" name="btnSave"><@label
                                key="save.B">保存</@label></button>
                        </div>
                    </div>
                    <div class="buttonActiveGrey" style="margin-left: 10px;">
                        <div class="buttonContent">
                            <button type="button" class="close"><@label
                                key="close.B">关闭</@label></button>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </form>
</div>
<script type="text/javascript">


(function($){
    var page = DWZ.context();
    var messageRuleItemTbody = $("tbody[name='messageRuleItem_tbody']",page);
    var messageRuleItemRowNumber = $("tr",messageRuleItemTbody).length;
    
    var ruleAndonAssignTbody = $("tbody[name='ruleAndonAssign_tbody']",page);
    var ruleAndonAssignRowNumber = $("tr",ruleAndonAssignTbody).length;
   
    
    $.messageRule = {
    		bringBackToRuleItemGrid : function(data){
    			var page = DWZ.context();
    			var prefix = "messageRuleItemList["+messageRuleItemRowNumber+"]"
    			
    			var trHtml = "<tr><td><input type='checkbox' name='rule_id'></td>"
    			trHtml += "<td><input type='hidden'  name='"+prefix+".periodStart'/>"+
    			              "<input type='hidden'  name='"+prefix+".periodEnd'/>"+data.periodStart +" - "+ data.periodEnd+"</td>";
    			trHtml += "<td><input type='hidden'  name='"+prefix+".timerStartEcode'/>"+data.timerStartEcodeText+"</td>";
    			trHtml += "<td><input type='hidden'  name='"+prefix+".statusEcode'/>"+data.statusEcodeText+"</td>";
    			trHtml += "<td><input type='hidden'  name='"+prefix+".receiveUser'/>"+data.receiveUserText+"</td>";
    			trHtml += "<td><input type='hidden'  name='"+prefix+".timeInterval'/>"+data.timeIntervalText+"</td>";
    			trHtml += "<td><input type='hidden'  name='"+prefix+".messageCode'/>"+data.messageCodeText+"</td>";
    			trHtml += "</tr>";
    			
    			messageRuleItemTbody.append(trHtml);
    			
    			$.each(data,function(name,value){
    				$("input[type='hidden'][name='"+prefix+"."+name+"']",$("tr:last",messageRuleItemTbody)).val(value);
    			});
    			
    			 $.jTableTool.initGridColumnWidth(messageRuleItemTbody.parents(".grid"));
    			 
    			 messageRuleItemRowNumber++;
    	    },
    	    bringBackToAndonGrid : function(datas){
    	    	var page = DWZ.context();
    	    	
    	    	
    	    	if(datas){
    	    		$.each(datas,function(index,data){
    	    			if($("tr[name='"+data["workUnitCode"]+"_"+data["andonCode"]+"']",ruleAndonAssignTbody).length>0){
    	    				return;
    	    			}
    	    			
    	    			var prefix = "MessageRuleAndonAssignList["+ruleAndonAssignRowNumber+"]";
    	    			var trHtml = "<tr name='"+data["workUnitCode"]+"_"+data["andonCode"]+"'>";
    	                trHtml += "<td><input type='hidden'  name='"+prefix+".workUnitCode' value='"+data["workUnitCode"]+"'/>"+
    	                                "<input type='hidden'  name='"+prefix+".andonCode'  value='"+data["andonCode"]+"'>"+
    	                                data["workCenterText"]+"</td>";
    	                    trHtml += "<td>"+data["workUnitText"]+"</td>";
    	                    trHtml += "<td>"+data["andonTypeText"]+"</td>";
    	                    trHtml += "<td>"+data["andonCode"]+"</td>";
    	                    trHtml += '<td><a title=\'<@label key="delete.B">删除</@label>\' class="btnDel" ><@label key="delete.B">删除</@label></a></td>';
    	                    trHtml += "</tr>";
    	    			
    	                    ruleAndonAssignTbody.append(trHtml);
    	                    $("a[class='btnDel']:last",ruleAndonAssignTbody).on("click",function(){
    	                    	$(this).parents("tr").remove();
    	                    	 $.messageRule.initGridColumnWidth(ruleAndonAssignTbody.parents(".grid"));
    	                    });
    	                    
    	                    ruleAndonAssignRowNumber++;
    	    		})
                    $.jTableTool.initGridColumnWidth(ruleAndonAssignTbody.parents(".grid"));
    	    	}
    	    },
    	    initGridColumnWidth:function($grid){
    	        var $ths = $(".gridThead thead>tr:first>th", $grid), $trs = $(".gridTbody tbody>tr:visible:first>td", $grid);
    	        $.each($ths, function(index, th){
    	            $($trs[index]).css('width', th.style.width);
    	        });
    	    }
    }
    
    
    $("a[class='btnDel']",ruleAndonAssignTbody).on("click",function(){
        $(this).parents("tr").remove();
        $.messageRule.initGridColumnWidth(ruleAndonAssignTbody.parents(".grid"));
    });
    
    $("a[name='btnMessageRuleItemDel']",page).on("click",function(){
        $.each($("input[type='checkbox']:checked",messageRuleItemTbody),function(index,el){
        	var trEl = $(el).parents("tr");
        	if(trEl.attr("ref")){
        		$("input[group='delete']",trEl).val("true");
        		trEl.hide();
        	}else{
        		trEl.remove();
        	}
        })
        $.messageRule.initGridColumnWidth(messageRuleItemTbody.parents(".grid"));
    })
    
    
    $("button[name='btnAndonSelect']",page).on('click',function(){
    	$.pdialog.open("${rc.getContextPath()}/manage/andon/andonLookUp?lockFlag=0","messageRuleItemAdd_dialog","ANDON选择",{
            width : 850,
            height : 550,
            minable : false,
            mask : true,
            resizable : true
        });
    	return false;
    })
    
    $("input[type='checkbox'][name='allAndonsFlag']",page).on('click',function(){
    	if($(this).attr("checked")){
    		//如果勾选了，则删除表格中所有记录，并设置选择按钮不可用
    		$("button[name='btnAndonSelect']",page).attr("disabled","disabled");
    		ruleAndonAssignTbody.html("");
    	}else{
    		$("button[name='btnAndonSelect']",page).removeAttr("disabled");
    	}
    })
    
    page.on('uiComplete', function() {
    	setTimeout(function(){
    			$(".pageFormContent:first",page).css("overflow","hidden");
    	},100);
    	$('.gridScroller', page).each(function(index,item){
    		$(item).css({
                maxWidth: $(item).width()
            })
    	})
    })
    
    
})(jQuery);
</script>
